ihelpuoo.http.POST_CONTENT_TYPE = 'application/x-www-form-urlencoded';

ihelpuoo.http.GET = function(url)
{
	var oRequest = ihelpuoo.http.createHttpRequest();
	oRequest.open("GET",url,false);
	oRequest.send(null);
	var re = new ihelpuoo.http.Response();
	re.status = oRequest.status;
	re.text = oRequest.responseText;
	return re;
}

ihelpuoo.http.POST = function(url,data)
{
	var oRequest = ihelpuoo.http.createHttpRequest();
	oRequest.open("post",url,false);
	oRequest.setRequestHeader('Content-Type',ihelpuoo.http.POST_CONTENT_TYPE);
	oRequest.send(data);
	var re = new ihelpuoo.http.Response();
	re.status = oRequest.status;
	re.text = oRequest.responseText;
	return re;
}

ihelpuoo.http.GETString = function(url)
{
	var re = ihelpuoo.http.GET(url);
	return re.text; 
}

ihelpuoo.http.POSTString = function(url,data)
{
	var re = ihelpuoo.http.POST(url,data);
	oRequest.setRequestHeader('Content-Type',ihelpuoo.http.POST_CONTENT_TYPE);
	return re.text; 
}

ihelpuoo.http.GETXML = function(url)
{
	ihelpuoo.loader().draw();
	var oRequest = ihelpuoo.http.createHttpRequest();
	oRequest.open("GET",url,false);
	oRequest.send(null);
	return ihelpuoo.http.buildXMLObjectByRequest(oRequest);
}

ihelpuoo.http.POSTXML = function(url,data)
{
	ihelpuoo.loader().draw();
	var oRequest = ihelpuoo.http.createHttpRequest();
	oRequest.open("POST",url,false);
	oRequest.setRequestHeader('Content-Type',ihelpuoo.http.POST_CONTENT_TYPE);
	oRequest.send(data);
	return ihelpuoo.http.buildXMLObjectByRequest(oRequest);
}

ihelpuoo.http.buildXMLObjectByRequest = function(oRequest)
{
	if(oRequest.responseText.length>0)
	{
		try
		{
			var xml = oRequest.responseXML;
			if(xml==null || !xml.documentElement)
			{
				xml = new ActiveXObject("msxml2.DOMDocument.3.0");
				xml.loadXML(oRequest.responseText);
			}
			if(ihelpuoo.xml.isForError(xml))
			{
				var es = new ihelpuoo.ErrorList(xml.documentElement);
				ihelpuoo.widget.error.getErrorView().draw(es);
				ihelpuoo.loader().hide();
				return null;
			}
			ihelpuoo.loader().hide();
			return xml;
		}
		catch(E)
		{
			var es = new ihelpuoo.ErrorList();
			es.addError(E.toString());
			ihelpuoo.widget.error.getErrorView().draw(es);
		}
	}
	ihelpuoo.loader().hide();
	return null;
}

/**
 * Create a HTTP Request object by different brower supporting.
 * 
 * @return {XMLHttpRequest} A HTTP Request object
 */
ihelpuoo.http.createHttpRequest = function()
{
	if (typeof XMLHttpRequest != "undefined")
	{
		return new XMLHttpRequest();
	}
	else if	(window.ActiveXObject)
	{
		var aVersions = [ "MSXML2.XMLHttp.5.0",
			"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
			"MSXML2.XMLHttp","Microsoft.XMLHttp"
			];
		for (var i = 0; i < aVersions.length; i++) {
			try {
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			} catch (oError) {
			//Do nothing
			}
		}
	}
	throw new Error("XMLHttp object could be created.");
}

/**
 * @return Unify String for each second.
 */
ihelpuoo.http.TimeBadge = function()
{
	return Date().toString().replace(/ |:/g,"");
}

